package com.ruoyi.web.controller.GoodsAttach;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.GoodsAttach.domain.GoodsAttach;
import com.ruoyi.GoodsAttach.service.IGoodsAttachService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 商品图片 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-19
 */
@Controller
@RequestMapping("/GoodsAttach/goodsAttach")
public class GoodsAttachController extends BaseController
{
    private String prefix = "GoodsAttach/goodsAttach";
	
	@Autowired
	private IGoodsAttachService goodsAttachService;
	
	@RequiresPermissions("GoodsAttach:goodsAttach:view")
	@GetMapping()
	public String goodsAttach()
	{
	    return prefix + "/goodsAttach";
	}
	
	/**
	 * 查询商品图片列表
	 */
	@RequiresPermissions("GoodsAttach:goodsAttach:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(GoodsAttach goodsAttach)
	{
		startPage();
        List<GoodsAttach> list = goodsAttachService.selectGoodsAttachList(goodsAttach);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商品图片列表
	 */
	@RequiresPermissions("GoodsAttach:goodsAttach:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsAttach goodsAttach)
    {
    	List<GoodsAttach> list = goodsAttachService.selectGoodsAttachList(goodsAttach);
        ExcelUtil<GoodsAttach> util = new ExcelUtil<GoodsAttach>(GoodsAttach.class);
        return util.exportExcel(list, "goodsAttach");
    }
	
	/**
	 * 新增商品图片
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品图片
	 */
	@RequiresPermissions("GoodsAttach:goodsAttach:add")
	@Log(title = "商品图片", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(GoodsAttach goodsAttach)
	{		
		return toAjax(goodsAttachService.insertGoodsAttach(goodsAttach));
	}

	/**
	 * 修改商品图片
	 */
	@GetMapping("/edit/{key}")
	public String edit(@PathVariable("key") int key, ModelMap mmap)
	{
		GoodsAttach goodsAttach = goodsAttachService.selectGoodsAttachById(key);
		mmap.put("goodsAttach", goodsAttach);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品图片
	 */
	@RequiresPermissions("GoodsAttach:goodsAttach:edit")
	@Log(title = "商品图片", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(GoodsAttach goodsAttach)
	{		
		return toAjax(goodsAttachService.updateGoodsAttach(goodsAttach));
	}
	
	/**
	 * 删除商品图片
	 */
	@RequiresPermissions("GoodsAttach:goodsAttach:remove")
	@Log(title = "商品图片", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(goodsAttachService.deleteGoodsAttachByIds(ids));
	}
	
}
